<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改产品品牌')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <script th:src="@{/js/jquery.min.js}"></script>
    <!--	<th:block th:include="include :: summernote-css" />-->
    <th:block th:include="include :: jasny-bootstrap-js" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-brand-edit" th:object="${brand}">
            <input id="brandId" name="brandId" th:field="*{brandId}"  type="hidden">



            <div class="form-group">
                <label class="col-sm-2 control-label is-required">品牌名称：</label>
                <div class="col-sm-10">
                    <input id="brandName" name="brandName" th:field="*{brandName}" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group form-group1">
                <label class="col-sm-2 control-label is-required">品牌图片：</label>
                <div class="col-sm-10 fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-preview thumbnail"  data-trigger="fileinput" style="width: 200px; height: 150px;">
                        <img th:src="*{brandImage}" alt="" />
                    </div>
                    <input type="hidden" name="brandImage" id="brandImage" th:value="*{brandImage}">
                    <div>
						<span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span>
							<span class="fileinput-exists">更改</span><input type="file" name="uploadImage"  id="uploadImage"></span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">状态：</label>
                <div class="col-sm-10">
                    <select id="post" class="form-control select2-multiple" name="isShow" >
                        <option value="1"  th:selected="*{isShow == 1}">显示</option>
                        <option value="0" th:selected="*{isShow == 0}">隐藏</option>

                    </select>
                </div>
            </div>




            <div class="form-group">
                <label class="col-sm-2 control-label is-required">显示排序：</label>
                <div class="col-sm-10">
                    <input class="form-control" type="text" name="orderNum" th:field="*{orderNum}"  required>
                </div>
            </div>
		</form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "goods/brand";

        $('#uploadImage').on('change.bs.fileinput ', function (e) {
            // 处理自己的业务
            var file = this.files[0];
            sendFile(file,"brandImage");
        });

        function sendFile(file,elemId) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $('#'+elemId).val(result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }
    
	    // $(function() {
		//     $('.summernote').summernote({
		//     	placeholder: '请输入公告内容',
		//     	height : 192,
		// 		lang : 'zh-CN',
		// 		followingToolbar: false,
		// 		dialogsInBody: true,
		// 		callbacks: {
	    //             onImageUpload: function (files) {
	    //                 sendFile(files[0], this);
	    //             }
	    //         }
		//     });
		// 	var content = $("#brandContent").val();
		//     $('#editor').summernote('code', content);
	    // });
	    
	    // 上传文件
	    // function sendFile(file, obj) {
	    //     var data = new FormData();
	    //     data.append("file", file);
	    //     $.ajax({
	    //         type: "POST",
	    //         url: ctx + "common/upload",
	    //         data: data,
	    //         cache: false,
	    //         contentType: false,
	    //         processData: false,
	    //         dataType: 'json',
	    //         success: function(result) {
	    //             if (result.code == web_status.SUCCESS) {
	    //             	$(obj).summernote('editor.insertImage', result.url, result.fileName);
		// 			} else {
		// 				$.modal.alertError(result.msg);
		// 			}
	    //         },
	    //         error: function(error) {
	    //             $.modal.alertWarning("图片上传失败。");
	    //         }
	    //     });
	    // }
	    
		$("#form-brand-edit").validate({
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	// var sHTML = $('.summernote').summernote('code');
				// $("#brandContent").val(sHTML);
				$.operate.save(prefix + "/edit", $('#form-brand-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
